home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4444 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.mindlink.net!news
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: a question on "return"
  5. Date: Sun, 04 Feb 1996 17:58:47 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4f2s87$b6u@fountain.mindlink.net>
  8. References: <4f2ipq$kaf@srvr1.engin.umich.edu>
  9. NNTP-Posting-Host: line200.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. cjlin@news-server.engin.umich.edu (Chih-Jen Lin) wrote:
  13.  
  14. >In C, usually we treat 1 as true and 0 as false.
  15.  
  16.      Not quite!  It's NON-ZERO as true and 0 as false.
  17.  
  18. >However, we usually use return(0) after normal end of an int
  19. >function and return(1) when some errors happen.
  20.  
  21.      The parens are redundant.
  22.           return 0;
  23. is syntactically correct code.
  24.  
  25. >Can some one tell me why we return a false value after normal 
  26. >end of a function ?
  27.  
  28.      We don't.  You are mixing levels of abstraction.  That 0 can be
  29. considered false is irrelevant.  It can also be considered as the NUL
  30. char in ASCII which is also irrelevant.
  31.  
  32.      If one is numbering error codes, one usually needs only one error
  33. code for success, but may need many for errors.  0 is a more distinct
  34. value: there are many positive numbers, but only one zero.  e.g.  A
  35. routine might return:
  36.           0     operation successful
  37.           1     file does not exist or is not accessible
  38.           2     file has internal consistency errors
  39.           3     out of memory
  40.           4     other failure
  41. and you would probably do different things to correct each error.
  42.  
  43. >Thanks in advance.
  44.  
  45. >Chih-Jen Lin 
  46.  
  47. Sincerely,
  48.  
  49. Gene Wirchenko
  50.  
  51. C Pronunciation Guide:
  52.      y=x++;     "wye equals ex plus plus semicolon"
  53.      x=x++;     "ex equals ex doublecross semicolon"
  54.  
  55.